﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace GUI_Web
{
    public partial class MasterPage1 : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string login = HttpContext.Current.User.Identity.Name;

                if (login == "facens")
                    TrocaLogin(false);

                litLogin.Text = login;
            }
        }

        protected void linkEsqueceu_Click(object sender, EventArgs e)
        {
            Response.Redirect("public/EsqueceuSenha.aspx");
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            if (txtUser.Text == "facens" && txtSenha.Text == "facens")
            {
                FormsAuthentication.RedirectFromLoginPage(txtUser.Text, false);     // cria cookie e redireciona para o url q ta no url

                TrocaLogin(false);
            }
            else
            {
                lblMsg.Text = "Usuário ou senha incorretos";
            }
        }

        private void TrocaLogin(bool chave)
        {
            divLogin.Visible = chave;
            divLogado.Visible = !chave;
        }

        protected void btnLogout_Click(object sender, EventArgs e)
        {
            TrocaLogin(true);
            FormsAuthentication.SignOut();

            Response.Redirect("Default.aspx");
        }
    }
}